﻿package Gameplay.Water
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.utils.getDefinitionByName;
	
	public class WaterTiles 
	{
		public static const TILE_WIDTH:int = 42;
		public static const TILE_HEIGHT:int = 64;
		
		private static var FClasses:Vector.<Class>;
		private static var FCount:int;
		
		public function WaterTiles():void
		{}
		
		public static function set Count(ACount:int):void
		{
			if (!FClasses)
				FClasses = new Vector.<Class>;	
				
			FCount = ACount;
			
			for (var i:int = 0; i < ACount; i++)			
				FClasses.push(getDefinitionByName('WaterTile_' + i) as Class);			
		}
		
		public static function ClassAt(AIndex:int):Class
		{
			return FClasses[AIndex];
		}
		
		public static function BitmapAt(AIndex:int):Bitmap
		{
			var vClass:Class = ClassAt(AIndex);			
			var vData:BitmapData = BitmapData(new vClass());
			vClass = null;
			return new Bitmap(vData);
		}
		
		public static function get RandomBitmap():Bitmap
		{
			return BitmapAt(Math.floor(Math.random() * FClasses.length));
		}
	}	
}
